
package mrirnaproject;


import java.io.BufferedWriter;
import java.io.File;  
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Scanner;

import org.biojava3.core.exceptions.CompoundNotFoundError;
import org.biojava3.core.sequence.DNASequence;
import org.biojava3.core.sequence.RNASequence;
import org.biojava3.core.sequence.io.FastaReaderHelper;



@SuppressWarnings("unused")
//class used to read DNA files and get the mRNA sequence from it
public class inputRefFile{
	
	public inputRefFile(){
		
	}
    @SuppressWarnings("resource")
	public static String readDNA() throws IOException{
    	
    	Scanner sc = new Scanner(System.in);
		String subPattern = "";
		Scanner input = null;
		
		System.out.println("Input the file path for the DNA file you wish to use: \n");
	
		boolean isFile = false;
		
		while (isFile == false){    

		    String fileName = sc.next();
		    File inputFile = new File(fileName);
        //scanning the file provided
		    if (inputFile.exists()){
		        input = new Scanner(inputFile);
		        isFile = true;
		    }            
		    char c = input.next().charAt(0);
		//condition to skip the fasta file header
		    if(c == '>'){
			
			input.nextLine();
		    while(input.hasNextLine()){
		    subPattern = subPattern + input.nextLine();
		    }
		}
		    else {
		    	while(input.hasNextLine()){
				    subPattern = subPattern + input.nextLine();
		    }
		    }
		}
	
		    
		//getting the RNA sequence from the DNA
		DNASequence DNAfile = new DNASequence(subPattern);
		RNASequence RNAfile = DNAfile.getRNASequence();
		String name = "mRNA.txt";
		FileWriter writemrna = new FileWriter(name);
		BufferedWriter wmrna = new BufferedWriter(writemrna);
		String mRNA = RNAfile.toString();
		//saving to a file
		wmrna.write(mRNA);
	    wmrna.close();
		
	    return name;
	
    }
	
	public static void main(String[] args) throws Exception {
		
		//testing if it works
		String name = readDNA();
		
	
	}

	}

		
	

